import request from '@/utils/request'
import store from '@/store'
// 查询ChildClockLog列表
export function listChildClockLog(childId, query) {
    return request({
        url: '/api/v1/childClockLogList/' + childId,
        method: 'get',
        params: query
    }).then(function (res) {
         
        let clockStatus = store.getters.parameter.clock_status;
       
        res.data.list.forEach((item, index) => {
            
            for (let key in item) {
                 
                if (key == "clockStatus") {
                    item[key] = getDictLabelByValue(item[key],clockStatus)
                }
                if (key == "sleep") {
                    //sleep.sleepDuration
                    item[key].sleepDuration = toHourMinute(item[key].sleepDuration )
                }
               

            }
             
            res.data.list[index] = item
        });
        // console.log(res.data.list)
        return res;

    })
}


function getDictLabelByValue(value, dict_list) {
    let dictLabel = "";
    if (dict_list) {
        dict_list.forEach((_item, index) => {
            if (_item.dictValue == value) {
                dictLabel = _item.dictLabel
            }
        })
        return dictLabel;
    } else {
        console.log(value);
        return;
    }

}

function toHourMinute(minutes){
    return (Math.floor(minutes/60) + "小时" + (minutes%60) + "分" );
    // 也可以转换为json，以方便专外部使用属
    // return {hour:Math.floor(minutes/60),minute:(minutes%60)};
  }
  

// 查询ChildClockLog详细
export function getChildClockLog(clockLogId) {
    return request({
        url: '/api/v1/childClockLog/' + clockLogId,
        method: 'get'
    })
}



// 删除ChildClockLog
export function delChildClockLog(clockLogId) {
    return request({
        url: '/api/v1/childClockLog/' + clockLogId,
        method: 'delete'
    })
}